<?php


namespace App\Http\Resources\news;


use App\Models\news\News;
use App\Models\user\Collect;
use Illuminate\Http\Resources\Json\ResourceCollection;

class CollectResource extends ResourceCollection
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'total' => $this->resource->total(),
            'perPage' => $this->resource->perPage(),
            'current_page' => $this->resource->currentPage(),
            'items' => $this->collection->map(function (Collect $item) {
                return [
                    'user_id' => $item->user_id,
                    'resource_id' => $item->resource_id??'',
                    'status' => $item->status,
                    'type' => $item->type,
                    'comment_number' => $item->comment_number,
                    'news' => $item->type == 1 ? $item->news : null,
                    'exams' => $item->type == 2 ? $item->exams : null
                ];
            })
        ];
    }
}